import advice.CustomAdvice;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.asm.Advice;
import service.impl.HelloServiceImpl;

import static net.bytebuddy.matcher.ElementMatchers.named;

public class MainApplication {
    public static void main(String args[]) throws IllegalAccessException, InstantiationException {
        HelloServiceImpl impl= new ByteBuddy()
                .subclass(HelloServiceImpl.class)//归入对象
                .method(named("sayHello"))//作用范围
                .intercept(Advice.to(CustomAdvice.class))//拦截实现
                .make()
                .load(MainApplication.class.getClassLoader())
                .getLoaded()
                .newInstance();
        impl.sayHello();
    }
}
